package elitech.vietnam.myfashion.view;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;

import elitech.vietnam.myfashion.MainActivity;
import elitech.vietnam.myfashion.R;
import elitech.vietnam.myfashion.config.Const;
import elitech.vietnam.myfashion.dialog.UserInfoDialog;
import elitech.vietnam.myfashion.entites.Comment;
import elitech.vietnam.myfashion.widgets.ExTextView;

public class CommentView extends LinearLayout implements View.OnClickListener {
	
	private Comment mComment;
	private TextView mTxtUserName, mTxtTime;
//	private ExTextView mTxtComment;
	TextView mTxtComment;
	private ImageView mAvatar;
	
	public CommentView(Context context, Comment comment) {
		super(context);
		this.mComment = comment;
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(inflater != null){
            inflater.inflate(R.layout.item_comment, this);
        }
		
		mAvatar = (ImageView) findViewById(R.id.icom_avatar);
		mTxtUserName = (TextView) findViewById(R.id.icom_username);
		mTxtComment = (TextView) findViewById(R.id.icom_comment);
		mTxtTime = (TextView) findViewById(R.id.icom_time);
		
//		new DownloadImageTask(context, mAvatar, true).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, comment.Image);
		UrlImageViewHelper.setUrlDrawable(mAvatar, Const.SERVER_IMAGE_THUMB_URL + comment.Image, R.drawable.no_avatar);
		
		mTxtUserName.setText((mComment.NickName.equals("")) ? mComment.Name : mComment.NickName);
		mTxtComment.setText(Html.fromHtml(mComment.Content));
		mTxtTime.setText(mComment.Date);
		
		mAvatar.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v.getId()==R.id.icom_avatar) {
			new UserInfoDialog((MainActivity) getContext(), mComment.AccountID).show();
		}
	}
	
}
